//
//  UserCenterViewCell.m
//  SinaWebo
//
//  Created by wwj on 16/6/29.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "UserCenterViewCell.h"
#import "CardGroup.h"
#import "UserCenterBtn.h"
#import "Pic.h"

@interface UserCenterViewCell ()
@property (weak, nonatomic) IBOutlet UIView *centerView;
@property (weak, nonatomic) IBOutlet UILabel *lifetL;
@property (weak, nonatomic) IBOutlet UILabel *rightL;
@end

@implementation UserCenterViewCell

- (void)awakeFromNib{
    for (NSInteger index = 0; index < 3; index++) {
        UserCenterBtn *btn = [[UserCenterBtn alloc] init];
        [self.centerView addSubview:btn];
    }
}

- (void)setGroupArray:(NSArray *)groupArray{
    _groupArray = groupArray;
    
    [self setupTopView];
    [self setupCenterView];
}

- (void)setupTopView{
    CardGroup *title = _groupArray.firstObject;;
    _lifetL.text = title.desc;
    _rightL.text = title.title_extra_text;
}

- (void)setupCenterView{
    CardGroup *cardGroup = _groupArray.lastObject;
    CGFloat margin = 15;
    CGFloat pading = 10;
    NSInteger count = cardGroup.pics.count?cardGroup.pics.count:cardGroup.items.count;
    CGFloat btnW = (kScreenW - 2*margin - (count-1)*pading) / count;
    CGFloat btnH = _centerView.height;
    for (int index = 0; index < count; index++) {
        Pic *pic = cardGroup.pics.count?cardGroup.pics[index]:cardGroup.items[index];
        UserCenterBtn *btn = self.centerView.subviews[index];
        btn.pic = pic;
        btn.x = margin + (pading + btnW) * (index%count);
        btn.y = 0;
        btn.width = btnW;
        btn.height = btnH;
    }
}

@end
